import cookie from '@/utils/cookie.js'

import store from '@/store'
import {
	getAreaList,
	getBannerList,
	getNoticeList
} from '@/api/dict.js'
const map = {
	getAreaList,
	getBannerList,
	getNoticeList
}
const state = {
	AreaList: [],
	BannerList: [],
	NoticeList: [],
	
	applyItemData: [], // 报名列表
}
const mutations = {
	setState(state, {
		mapKey,
		value
	}) {
		state[mapKey] = value
	},
	
	
	/**
	 * 修改报名列表
	 */
	setApplyItemData(state,value){
		state.applyItemData = value
	}
}
const actions = {
	async getState({
		state,
		commit,
		getters,
		dispatch,
		rootGetters
	}, {
		mapKey,
		isReset = false
	}) {
		// if (!isReset && state[mapKey].length) return
		const res = await map[`get${mapKey}`]()
		
		if (mapKey === 'NoticeList') {
			commit('setState', {
				mapKey,
				value: res.rows
			})
		} else {
			commit('setState', {
				mapKey,
				value: res.data
			})
		}
	},
}
const getters = {
	AreaList(state) {
		return state.AreaList
	},
	BannerList(state) {
		return state.BannerList
	},
	NoticeList(state) {
		return state.NoticeList
	},
	locationAreaList(state) {
		return state.AreaList.map(i => ({
			...i,
			text: i.name,
			value: i.code
		}))
	},
	barText(state) {
		const barText = state.NoticeList.length ? state.NoticeList[0].content : ''
		return barText;
	}
}
export default {
	state,
	mutations,
	actions,
	getters
}
